// pages/defect/craft/params/index.js


Component({
  /**
   * 组件的属性列表
   */
  properties: {
    dataSource: {
      type: Array,
      value: []
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    form: {
      max: '',
      min: '',
      val: {}
    },
    name: '参数',

    show: false
  },

  /**
   * 组件的方法列表
   */
  methods: {
    onCancel() {
      this.triggerEvent('cancel');
    },
    onSubmit(event) {
      const values = event.detail.value;
      if(values['ign'] && values['maxNumber'] && values['minNumber']) {
        this.triggerEvent('submit',{
          ingredientsId: this.data.form['val']['id'],
          maxNumber: values['maxNumber'],
          minNumber: values['minNumber']
        })
      }
    },
    initData(data) {
      this.setData(data)
    },
    setDefaultValue(form) {
      this.setData({
        form
      })
    },
    onSelect(event) {
      const values = event.detail;
      this.setData({
        form: {
          ...this.data.form,
          val: values
        },
 
      })
      this.onSelectorHide();
    },
    onInput(event) {
      const value = event.detail,
        key = event.currentTarget.dataset.key;
      const form = this.data.form;
      form[key] = value;
      this.setData({
        form
      })
    },
    onClear() {
      this.setData({
        form: {
          max: '',
          min: '',
          val: {}
        }
      })
    },
    onSelectorShow() {
      this.setData({
        show: true
      })
    },
    onSelectorHide() {
      this.setData({
        show: false
      })
    },
  },
  lifetimes: {
    attached() {
      //this.fetchList()

    }
  }
})